package com.imooc.mythreadpool;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author liansen
 * @create 05-11-13:34
 */
@Component
public class MyThreadPoolExecutor {

    @Bean
    public ThreadPoolExecutor myThreadPool() {
        /**
         * int corePoolSize,
         * int maximumPoolSize,
         * long keepAliveTime,
         * TimeUnit unit,
         * BlockingQueue<Runnable> workQueue,
         * ThreadFactory threadFactory,
         * RejectedExecutionHandler handler
         */
        return new ThreadPoolExecutor(3, 9, 20L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(6), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

    }
}
